package com.groot.system.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.groot.common.exception.BusinessException;
import com.groot.common.web.BaseController;
import com.groot.common.web.pager.PagerVo;
import com.groot.system.entity.Menu;
import com.groot.system.service.IMenuService;

@Controller
@RequestMapping("/admin/system/menu")
public class MenuController extends BaseController {

	@Autowired
	private IMenuService menuService ;
	
	@RequestMapping(value={"","/index"})
	public String main_page() {
		return "test/menu_main" ;
	}
	
	@RequestMapping(value="menus/page")
	public String menus(Menu menu, Model model) throws Exception {
		int i = 1 ;
		if(i==1) {
			throw new BusinessException("menu", "Menu查询错误") ;
		}
		PagerVo<Menu> pager = this.menuService.pager(menu) ;
		model.addAttribute("pager", pager) ;
		return "test/menu_list" ;
	}
	
	@RequestMapping(value="menus/json")
	public @ResponseBody List<Menu> menus(Menu menu) {
		return this.menuService.list(menu) ;
	}
	
}
